home *** CD-ROM | disk | FTP | other *** search
- <!--- This example shows the use of CFBREAK to exit
- a loop when a condition is met --->
-
- <!--- select a list of courses and use CFLOOP to find a condition
- and then break the loop --->
- <!--- check that number is numeric --->
- <CFIF IsDefined("form.number")>
- <CFIF Not IsNumeric(form.number)>
- <CFABORT>
- </CFIF>
- </CFIF>
-
- <CFQUERY NAME="GetCourses" DATASOURCE="cfsnippets">
- SELECT *
- FROM Courses
- ORDER by Course_Num
- </CFQUERY>
-
- <HTML>
- <HEAD>
- <TITLE>
- CFBREAK Example
- </TITLE>
- </HEAD>
-
- <BODY bgcolor=silver>
- <H3>CFBREAK Example</H3>
-
- <P>This example uses CFLOOP to cycle through a query to find a desired value.
- (In our example, a list of values corresponding to courses in the Snippets datasource).
- When the conditions of the query are met, CFBREAK stops the loop.
-
- <P>Please enter a Course Number, and hit the "submit" button:
-
- <FORM ACTION="cfbreak.cfm" METHOD="POST">
- <SELECT NAME="courseNum">
- <CFOUTPUT query="GetCourses">
- <OPTION VALUE="#Course_Num#">#Course_Num#
- </CFOUTPUT>
- </SELECT>
- <INPUT TYPE="Submit" NAME="" VALUE="Search on my Number">
- </FORM>
-
- <!--- if the courseNum variable is not defined, don't loop
- through the query --->
- <CFIF IsDefined ("form.courseNum") is "True">
-
- <!--- loop through the query until desired value is found,
- then use CFBREAK to exit the query --->
- <CFLOOP QUERY="GetCourses">
- <CFIF GetCourses.Course_Num is form.courseNum>
- <CFOUTPUT>
- <H4>Your Desired Course was found:</H4>
- <PRE>#Course_Num# #Descript#</PRE></CFOUTPUT>
- <CFBREAK>
- <CFELSE>
- <BR>Searching...
- </CFIF>
- </CFLOOP>
- </CFIF>
-
- </BODY>
- </HTML>
-